package service

import (
	"blizzard/app/dao"
	"blizzard/app/model"
	"blizzard/app/utils/tool"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

var SignView = new(serviceSignView)

type serviceSignView struct {}

func (s *serviceSignView) Add(r *ghttp.Request, m *model.AddSignCardParam) error {
	one, err := dao.BxCardType.FindOne("id = ?", m.CardTypeId)
	if err != nil {
		return err
	}
	admin := dao.BxMenber.GetAdmin()
	card := g.Map{}
	card["time"] = one.Time
	card["time_type"] = one.TimeType
	card["software_id"] = one.SoftwareId
	card["name"] = one.Name
	card["create_time"] = tool.GetTime()
	card["menber_id"] = admin.Id
	card["point"] = ""
	cardhead := one.Head
	body := make(map[int]string)
	for i := 0; i < m.Count; i++ {
		body[i] = cardhead + tool.GetCard(r)
		card["cardnum"] = body[i]
		_, err = dao.BxSingleCard.Save(card)
		if err != nil {
			return err
		}
	}
	return nil
}

func (s *serviceSignView) List() (interface{}, error) {
	all, err := dao.BxSingleCard.FindAll("id > ?", 0)
	if err != nil {
		return nil, err
	}
	return all, nil
}